﻿using DocumentFormat.OpenXml.Lite.Helper;
using DocumentFormat.OpenXml.Lite.Xml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace DocumentFormat.OpenXml.Lite.WordprocessingML.Word.Table.Properties
{
    [XmlRoot("tblLook", Namespace = Constants.WordMain)]
    public class Look : XmlSerializable, ITablePropElement
    {
        /// <summary>
        /// Hexadecimal number. Length: 4
        /// </summary>
        [XmlAttribute("val", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public string Value {
            get { return value; }
            set
            {
                if (value.Length != 4 || !Helpers.ParseHexadecimalValue(value))
                {
                    throw new ArgumentException("String: " + value +
                        "is not a valid hexadecimal string or length is not 4!");
                }
                this.value = value;
            }
        }

        [XmlIgnore]
        private string value;

        public Look() { }

        public void Copy(object obj)
        {
            if (obj is Look)
            {
                this.Value = (obj as Look).Value;
            }
        }
    }
}
